﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ATM : ICashMachine
{
   
    public event EventHandler<BigMoneyArgs> BigMoneyFetched;
    private Random random = new Random();

    public void Withdraw(Account acc, decimal amount)
    {
        // 模拟30%的概率出现坏钞情况
        if (random.NextDouble() < 0.3)
            throw new BadCashException("检测到坏钞，请重新操作！");

        // 调用账号的取款方法
        acc.Withdraw(amount);

        // 如果取款金额大于等于 10000 元，则触发大额取款事件
        if (amount >= 10000)
        {
            BigMoneyFetched?.Invoke(this, new BigMoneyArgs(acc, amount));
        }
    }
}
